package com.example.myappliu1012;

import androidx.appcompat.app.AppCompatActivity;

import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TimePicker;

import com.example.myappliu1012.Bean.Alamitem;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ListView lv;
    //  alt回车 找到 inner class   Alamitem就ok了

    private List<Alamitem> itemList= new ArrayList<>();
    private NaozhongAdapter4 adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        setListener();

    }

    //弹窗 监听 点击事件
    private void setListener() {
        //在item布局里 加入 foucusable=false

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                showTimer(position);
            }
        });






    }
        //显示时间
    private void showTimer( final int position) {
        TimePickerDialog td=new TimePickerDialog(MainActivity.this, 1,new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourofDay, int minute) {
                //获取点击位置数据源对象
                Alamitem a=itemList.get(position);
                //设置时间
                String h=hourofDay<10 ? "0"+hourofDay:""+hourofDay;
                String m=minute<10 ? "0"+minute:""+minute;
                a.setTime(h+":"+m);
                //由adapter适配器更新视图
                adapter.notifyDataSetChanged();
            }

        },0,0,true);

        td.show();
    }

    private void initView() {
//        lv.findViewById(R.id.lv);
        lv=findViewById(R.id.lv);
        //无参
        Alamitem a=new Alamitem();
        a.setTime("66:66");
        a.setIschecked(false);
        itemList.add(a);
        //有参
        Alamitem a1=new Alamitem("66:10",false);
        itemList.add(a1);
        Alamitem a2=new Alamitem("66:11",false);
        itemList.add(a2);


        Alamitem a3=new Alamitem("66:13",false);
        itemList.add(a3);
        Alamitem a4=new Alamitem("66:14",false);
        itemList.add(a4);

        Alamitem a5=new Alamitem("66:15",false);
        itemList.add(a5);

        adapter=new NaozhongAdapter4(MainActivity.this,R.layout.item,itemList);
        lv.setAdapter(adapter);



    }
}
